<template>
	<!-- 团购列表 -->
	<!--pages/aBulkList/aBulkList.wxml-->
	<view class="abulk-list-wrapper">
		<view class="banner">
			<view class="bg">
				<image src="/static/images/icon/group-bg.png"></image>
			</view>
			<view class="img">
				<image src="/static/images/icon/group-banner.png"></image>
			</view>
		</view>
		<view class="abulk-list">
			<!-- 商品项 -->
			<block v-for="(item, index) in aBulkList" :key="index">
				<view class="abulk-list-item" @tap="toAbulkListPage" :data-groupactivityid="item.groupActivityId"
					:data-prodid="item.prodId">
					<!-- 商品图片 -->
					<view class="prod-img">
						<image :src="item.prodPic"></image>
					</view>
					<!-- 商品信息 -->
					<view class="prod-msg">
						<view class="prod-title">
							<view class="prod-describe">{{item.groupNumber}} {{i18n.join}}</view>{{item.prodName}}
						</view>
						<view class="prod-price">
							<!-- 团购价 -->
							<view class="pic">
								<text class="symbol">￥</text>
								<text class="big-num">{{wxs.parsePrice(item.actPrice)[0]}}</text>
								<text class="small-num">.{{wxs.parsePrice(item.actPrice)[1]}}</text>
							</view>
							<!-- 原价 -->
							<view class="original-price">￥{{wxs.toPrice(item.price)}}</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<view class="empty" v-if="aBulkList.length==0">
			<view class="empty-icon">
				<image src="/static/images/icon/empty.png"></image>
			</view>
			<view class="empty-text">{{i18n.noMoreActivities}}</view>
		</view>
		<!-- <pageBottomTips :isAll="loadAll" :empty="!aBulkList.length" /> -->
		<pageBottomTips :isAll="loadAll" :current='current>1?true:false' />
	</view>
</template>

<script module="wxs" lang="wxs" src="../../../wxs/number.wxs"></script>

<script>
	const http = require("../../../utils/http.js")
	import pageBottomTips from '../../components/pageBottomTips/pageBottomTips'

	export default {
		data() {
			return {
				aBulkList: [],
				//商品列表
				current: 1,
				size: 20,
				pages: "",
				loadAll: false, // 已加载全部
			};
		},

		components: {
			pageBottomTips
		},
		computed: {
			i18n() {
				return this.$t('index')
			}
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.getAbulkList();
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			//头部导航标题
			uni.setNavigationBarTitle({
				title: this.i18n.groupBuyingList
			});
		},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			if (this.current < this.pages) {
				this.setData({
					current: this.current + 1
				});
				this.getAbulkList();
			} else {
				this.setData({
					loadAll: true
				})
			}
		},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			/**
			 * 获取团购商品列表
			 */
			getAbulkList: function() {
				uni.showLoading();
				var params = {
					url: "/groupProd/page",
					method: "GET",
					data: {
						current: this.current,
						size: this.size
					},
					callBack: res => {
						uni.hideLoading()
						var aBulkList = [];
						if (res.current == 1) {
							aBulkList = res.records;
						} else {
							aBulkList = this.aBulkList.concat(res.records);
						}
						if (res.total <= 4 && res.total > 0) {
							this.setData({
								loadAll: true
							})
						}
						this.setData({
							aBulkList: aBulkList,
							pages: res.pages,
							current: res.current
						});
					}
				};
				http.request(params);
			},

			/**
			 * 跳转到拼团商品详情
			 */
			toAbulkListPage: function(e) {
				var prodId = e.currentTarget.dataset.prodid;
				var groupActivityId = e.currentTarget.dataset.groupactivityid;
				this.$Router.push({
					path: '/packageProduct/pages/prod/prod',
					query: {
						prodid: prodId,
						groupActivityId: groupActivityId
					}
				})
			}
		}
	};
</script>
<style lang="scss">
	.abulk-list-wrapper {
		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}

		.banner {
			position: relative;
			width: 750rpx;
			height: 284rpx;
			padding-top: 24rpx;

			.bg {
				position: absolute;
				top: 0;
				left: 0;
				font-size: 0;
				width: 750rpx;
				height: 220rpx;
			}

			.img {
				font-size: 0;
				width: 710rpx;
				height: 280rpx;
				margin: 0 auto;
				position: relative;
			}

			image {
				border-radius: 0;
			}
		}

		.abulk-list {
			display: flex;
			flex-wrap: wrap;
			margin-top: 20rpx;


			.abulk-list-item {
				width: 345rpx;
				background: #fff;
				padding: 20rpx;
				box-sizing: border-box;
				margin-left: 20rpx;
				margin-bottom: 20rpx;
				border-radius: 10rpx;


				.prod-img {
					width: 305rpx;
					height: 305rpx;
					font-size: 0;
				}

				.prod-msg {
					margin-top: 20rpx;


					.prod-title {
						height: 80rpx;
						line-height: 40rpx;
						font-size: 28rpx;
						word-break: break-all;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						color: #000;

						.prod-describe {
							display: inline-block;
							line-height: 20rpx;
							font-size: 18rpx;
							color: white;
							padding: 6rpx 12rpx;
							background: #e43130;
							border-radius: 20rpx;
							margin-right: 6rpx;
						}
					}

					.prod-price {
						position: relative;
						height: 40rpx;
						line-height: 40rpx;
						font-family: Arial;
						margin-top: 20rpx;


						.pic {
							font-family: Arial;
							display: inline-block;
							color: #e43130;


							.symbol {
								font-size: 24rpx;
							}

							.big-num {
								font-size: 32rpx;
							}

							.small-num {
								font-size: 24rpx;
							}
						}

						.original-price {
							display: inline-block;
							color: #999;
							font-size: 24rpx;
							text-decoration: line-through;
							margin-left: 10rpx;
						}
					}
				}
			}
		}


		/* 加载完成 */
		.loadall {
			margin: 20rpx 0;
			line-height: 2em;
			font-size: 28rpx;
			color: #aaa;
			text-align: center;
		}

		/* 列表为空 */
		.empty {
			margin-top: 100rpx;
			text-align: cneter;


			.empty-icon {
				display: block;
				width: 80rpx;
				height: 80rpx;
				margin: 0 auto;
				margin-bottom: 20rpx;
			}

			.empty-icon>image {
				width: 100%;
				height: 100%;
			}

			.empty-text {
				font-size: 28rpx;
				text-align: center;
				color: #999;
				line-height: 2em;
			}
		}
	}
</style>
